/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.display.ui.combobox {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.display.service.MLButton;
	import com.googlecode.milib.display.ui.list.MCListAbstractElement;
	import com.googlecode.milib.vo.MLEventInfo;

	import flash.display.MovieClip;
	import flash.text.TextField;

	/**
	 * @author Marek Brun
	 */
	public class MCComboBoxListElement extends MCListAbstractElement implements IMLBroadcasterListener {
		
		public const event_Select : String = 'Select';
		
		private var mc_bg : MovieClip;
		private var mc_tfName : TextField;
		protected var bgBtn:MLButton;
		private var data:*;
		
		public function MCComboBoxListElement(mc:MovieClip) {
			super(mc);
			mc_bg=MovieClip(mc.getChildByName('bg'));
			mc_tfName=TextField(mc.getChildByName('tfName'));
			mc_tfName.mouseEnabled=false;
			bgBtn=mlmc.getMLButton('bg');
			bgBtn.addListener(this);
		}
		
		override public function setData(data:*):void {
			this.data=data;
			mc_tfName.htmlText=MCComboBoxItemVO(data).label;
		}
		
		public function getData():MCComboBoxItemVO {
			return data;
		}
		
		override public function doWidth():void {
			mc_bg.width=width;			mc_tfName.width=width;
		}
		
//********************************************************************************************
//		events for MCComboBoxListElement
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case bgBtn:
					switch(ev.event) {
						case bgBtn.event_Press:
							broadcastEvent(event_Select);
						break;
					}
				break;
			}
		}
		
	}
}

